// PCF8523实时时钟演示代码
// 使用了adafruit/RTClib

#include <cupeRTC.h>

const char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void CupeRTC::init()
{
  TwoWire *cupeWire = new TwoWire(RTC_SDA, RTC_SCL);
  rtc8563 = new RTC_PCF8563();
  
  if (!rtc8563->begin(cupeWire))
  {
    dbLog("\nCouldn't find RTC");
  }
  else
  {
    dbLog("\nRTC found!");
    if (rtc8563->lostPower())
    {
      dbLog("\nRTC is NOT initialized, let's set the time!");
      rtc8563->adjust(DateTime(F(__DATE__), F(__TIME__)));
    }
    rtc8563->start();
  }
}

void CupeRTC::loop()
{
  delay(1000);
  DateTime now = rtc8563->now();
  dbLog("\nThe time is: %02d:%02d:%02d %s, %d/%02d/%02d\n", now.hour(), now.minute(), now.second(), daysOfTheWeek[now.dayOfTheWeek()], now.day(), now.month(), now.year());
}
